function alert_facet(value_selected){
	document.getElementById('j_idt3:thequery').value += value_selected;
}

function populate(){
	raw_content = document.getElementById('raw_content').value;
	var temp_raw_content = raw_content.split("{");
	raw_content = temp_raw_content[1];
	temp_raw_content = raw_content.split("}");
	raw_content = temp_raw_content[0];
	
	var splitted = raw_content.split(","); 
	
	object_array = new Array();
	mydiv = new Array();									

	var pageDivs = document.getElementsByClassName("faccetta");
	for(i = 0; i < pageDivs.length;i++)
	{
		var query = splitted[i].split("=");
		
		mydiv[i] = pageDivs[i];
		
		var textual_query = new String('"' + query[0] + '"');
		var div = '<div><p>' + query[0] + '<br>' + query[1] + '<br><input type="button" value="Look!" id="' + query[0] + '"  onClick="alert_facet(this.id)"></div>';
		mydiv[i].innerHTML = div;
	}
}



document.querySelector('#cubo').addEventListener("mousemove", mouseOver, false);
document.querySelector('#cubo').addEventListener("click", select_face, false);
document.querySelector('#cubo').addEventListener("click", select_face_1, false);

var zoom_value = 1.0;					//Valore di default dello Zoom da aggiornare con gli appositi pulsanti
	
var paused = false;						//Utilizzato per mettere in pausa il cubo al primo click	
var avoid_selection = false;				//Utilizzato per fare il display di un alert alla selezione di un div
function set_paused(){	
	if(!paused) paused = true;	
	else paused = false;
}

function selected_facet(){
	avoid_selection = false;
	set_paused();
}

function mouseOver(e){	
	if(!paused){
		var y = e.pageX * -0.9,
		x = e.pageY * -0.9;
		rotate(x,y);
	}
	else{
		var classes, facet, info_box, target = e.target.parentNode;
		
		if (target.className && target.className.indexOf('faccetta') !== -1) {
				classes = target.className.split(' ');
				facet = classes[0];
				info_box = document.querySelector('#informazioni span');
				info_box.innerHTML = 'Classe Faccetta Selezionata: ' + facet;
		}
	}
}
function rotate(newX,newY){
	var x = parseInt(document.querySelector('#rotate_x').value,10) + (newX || 0),
	y = parseInt(document.querySelector('#rotate_y').value,10) + (newY || 0),
	
	cubo = document.getElementById('cubo');

	cubo.style.webkitTransform = "rotateX(" + x + "deg) rotateY(" + y + "deg)";
	cubo.style.MozTransform = "rotateX(" + x + "deg) rotateY(" + y + "deg)";
	cubo.style.transform = "rotateX(" + x + "deg) rotateY(" + y + "deg)";
}
function select_face(){	
		if(!paused) {
			set_paused();
			avoid_selection = true;
		}
		else{
		}
		/*
		DEPRECATED
		cubo.style.zoom = 1.5;
		cubo.style.MozTransform = 'scale(1.5)';
		cubo.style.WebkitTransform = 'scale(1.5)';
		*/
}

function select_face_1(){	
		if(avoid_selection == true) {
			avoid_selection = false;
		}
		else{			
			selected_facet();
		}
}

function zoom_in(){		
	cubo = document.getElementById('cubo');
	zoom_value = zoom_value + 0.25;
	cubo.style.zoom = zoom_value;
}

function zoom_out(){		
	cubo = document.getElementById('cubo');
	zoom_value = zoom_value - 0.25;
	cubo.style.zoom = zoom_value;
}

function strafe_left(){
	container = document.getElementById('cubo-container');
	container.style.left = "5%";							
}

							
function strafe_right(){
	container = document.getElementById('cubo-container');
	container.style.left = "55%";							
}

function strafe_center(){
	container = document.getElementById('cubo-container');
	container.style.left = "33%";							
}

